
$(document).ready(function() {
	var chatModal = (function () {/*
	<div id="chat-modal" class="modal show" tabindex="-1">
	  <div class="modal-dialog" role="document">
	    <div class="modal-content">
	      <div id="chat-body" class="modal-body">
	      	<div id="msg-div"></div>
	        <div id="div-video">
	            <video id="you-video" width="100%" height="100%" autoplay controls></video>
	        </div>
	        <div id="div-audio">
	            <audio id="you-audio" width="100%" height="100%" autoplay controls></audio>
	        </div>
	        <div id="div-word">
	        	<div id="word-div"></div>
	        </div>
	      </div>
	      <div class="modal-footer">
			<div class="btn-toolbar pull-left">
			    <div class="btn-group">
			        <input type="button" id="btn-video" class="btn btn-primary" value="视频" onclick="openVideo();" />
			    </div>
			</div>
			<div class="btn-toolbar pull-right">
			    <div class="btn-group">
	                <input type="text" id="txt-msg" class="form-control" placeholder="请输入消息" 
	                data-toggle="popover" data-placement="top" data-container="body">
			    </div>
			    <div class="btn-group">
			        <input type="button" id="btn-send" class="btn btn-primary" value="发送" onclick="sendMsg();" />
			    </div>
			</div>
	      </div>
	    </div>
	  </div>
	</div>
	*/}).toString().split('\n').slice(1, -1).join('\n');
	$(document.body).append(chatModal);
	
	var chatServer = 'http://192.168.0.101:9000';
	var cssUrl = chatServer + '/ruoyi/css/chat.css';
	var chatStyle = $("<link>")
	.attr({
		rel: "stylesheet",
		type: "text/css",
		href: cssUrl
	});
	$(document.body).append(chatStyle);
	
	var chatScript = (function () {/*
	<script type="text/javascript">
	    var wsServer = 'ws://192.168.0.101:9001/ws';
	    var wsAccount = '';
	    var wsSecret = '';
	    var pushServer = 'ws://192.168.0.101:2700';
	    var liveServer = 'http://192.168.0.101:8080/live/';
	    var liveDelay = 2500;
	</script>
	*/}).toString().split('\n').slice(1, -1).join('\n');
	$(document.body).append(chatScript);
	
	var jsUrl = chatServer + '/js/websock.js';
	$.getScript(jsUrl, function() {
		jsUrl = chatServer + '/ruoyi/js/chat.js';
		$.getScript(jsUrl, function() {
	    	checkLogin();
		});
	});
	jsUrl = chatServer + '/js/mpegts-1.7.2.min.js';
	$.getScript(jsUrl, function() {});
});
//校验消息，不支持动态加载
var checkError = function(error, element) {  
    var aij = $(element).attr('aij');
    var msg = aij + $(error).text();
	$.modal.msg(msg);
    msg = msg + '，请重新[' + aij + ']';
	var msgHead = "<b>AI</b>";
    var content = '<div class="msg-right">' + msgHead + ': ' + parseMsg(msg) + '</div>';
    $('#msg-div').append(content);
	procMsg(msg);
	$("#msg-div").scrollTop($("#msg-div")[0].scrollHeight);
};
$.validator.setDefaults({
	onfocusout: false,
	onkeyup: false,
	errorPlacement: checkError
});
$.extend($.validator.messages, {
    required: "不能为空",
    remote: "有误",
    email: "不是有效的电子邮件地址",
    url: "不是有效的网址",
    date: "不是有效的日期",
    dateISO: "不是有效的日期 (YYYY-MM-DD)",
    number: "不是有效的数字",
    digits: "不是有效的整数",
    creditcard: "不是有效的信用卡号码",
    equalTo: "不相同",
    extension: "不是有效的后缀",
    maxlength: $.validator.format("超过 {0} 个字符"),
    minlength: $.validator.format("少于 {0} 个字符"),
    rangelength: $.validator.format("长度不在 {0} 到 {1} 之间"),
    range: $.validator.format("范围不在 {0} 到 {1} 之间"),
    max: $.validator.format("大于 {0}"),
    min: $.validator.format("小于 {0}")
});
